
module.exports = function ($scope, $state, $stateParams,$resource,$modal,FileUploader,toaster, items, $modalInstance) {
  console.log('上传材料');
  console.log(items);
  $scope.item = items;
  $scope.a = {
    'project_code' : items.project_code,
    'project_file' : ''
  }
  var dic = {};
  if (items.project_file){
      $scope.material = JSON.parse(items.project_file);
      $scope.array1 = $scope.material.aa;
      dic.aa = $scope.array1;
      $scope.array2 = $scope.material.bb;
      dic.bb = $scope.array2;
      $scope.array3 = $scope.material.cc;
      dic.cc = $scope.array3;
      $scope.array4 = $scope.material.dd;
      dic.dd = $scope.array4;
      $scope.array5 = $scope.material.ee;
      dic.ee = $scope.array5;
      $scope.array6 = $scope.material.ff;
      dic.ff = $scope.array6;
      $scope.array7 = $scope.material.gg;
      dic.gg = $scope.array7;
      $scope.array8 = $scope.material.hh;
      dic.hh = $scope.array8;
      $scope.array9 = $scope.material.ii;
      dic.ii = $scope.array9;
  }
  $scope.del=function(index, number, str){
    console.log(index, number, str);
    if(number == '1'){
      $scope.array1.splice(index, 1);
      dic.aa = $scope.array1;
    }
    if(number == '2'){
      $scope.array2.splice(index, 1);
      dic.bb = $scope.array2;
    }
    if(number == '3'){
      $scope.array3.splice(index, 1);
      dic.cc = $scope.array3;
    }
    if(number == '4'){
      $scope.array4.splice(index, 1);
      dic.dd = $scope.array4;
    }
    if(number == '5'){
      $scope.array5.splice(index, 1);
      dic.ee = $scope.array5;
    }
    if(number == '6'){
      $scope.array6.splice(index, 1);
      dic.ff = $scope.array6;
    }
    if(number == '7'){
      $scope.array7.splice(index, 1);
      dic.gg = $scope.array7;
    }
    if(number == '8'){
      $scope.array8.splice(index, 1);
      dic.hh = $scope.array8;
    }
    if(number == '9'){
      $scope.array9.splice(index, 1);
      dic.ii = $scope.array9;
    }
    console.log(dic);
  }
  // $scope.arr = [];
  $scope.image = function(aa){
    var para = $state.get('app.imageupload');
    //设置上传文件夹，以自己业务命名
    angular.extend(para, {
      resolve : {  
        'dir' : function(){
          return 't1';
        }
      } 
    })
    var modalInstance = $modal.open(para);
    modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
      console.log('modal is opened');  
    });  
    modalInstance.result.then(function(result) {  
      if(aa == '1'){ // 材料1
        $scope.array1 = result;
        dic.aa = $scope.array1;
        console.log(dic);
      } else if(aa == '2'){
        $scope.array2 = result;
        dic.bb = $scope.array2;
        console.log(dic);
      } else if(aa == '3'){
        $scope.array3 = result;
        dic.cc = $scope.array3;
        console.log(dic);
      } else if(aa == '4'){
        $scope.array4 = result;
        dic.dd = $scope.array4;
        console.log(dic);
      } else if(aa == '5'){
        $scope.array5 = result;
        dic.ee = $scope.array5;
        console.log(dic);
      } else if(aa == '6'){
        $scope.array6 = result;
        dic.ff = $scope.array6;
        console.log(dic);
      } else if(aa == '7'){
        $scope.array7 = result;
        dic.gg = $scope.array7;
        console.log(dic);
      } else if(aa == '8'){
        $scope.array8 = result;
        dic.hh = $scope.array8;
        console.log(dic);
      } else if(aa == '9'){
        $scope.array9 = result;
        dic.ii = $scope.array9;
        console.log(dic);
      }
      // $scope.a.project_file = $scope.array.join(',');
    }, function(reason) {  
      console.log(reason);// 点击空白区域，总会输出backdrop  
      // click，点击取消，则会暑促cancel  
      $log.info('Modal dismissed at: ' + new Date());  
    }); 
  };
  // 提交
  $scope.submit = function(){
    console.log($scope.a);
    $scope.a.project_file = JSON.stringify(dic);
      $resource('/api/ac/ggc/reviewCompanyProjectService/createCompanyProject', {}, {}).save($scope.a, function(res){
          if(res.errcode === 0){ 
              toaster.success({title:"",body:'操作成功'});
              $modalInstance.close();
              $state.go('app.declarationList', {'type' : '1'});
          }else{
              toaster.error({title:"",body:res.errmsg});
          }
      });
    }
  
};
